import { ajaxService } from '@/utils/request';
import * as Type from './type';
const env = import.meta.env;
// const baseURL = env.VITE_DEV_BASE_URL;
const baseURL = env.VITE_APP_BASE_URL;
// const baseMapApi = 'http://127.0.0.1:3111';
const baseMapApi = env.VITE_GAODE_MAP_URL;

import mapBase from '@/utils/mapSdk';

/**
 *
 * @param params 【考勤项设置】列表
 * @returns
 */
export function GetAttendanceSetting() {
  return ajaxService<Type.TAttendanceSetting>({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_reminder/setting/list',
    method: 'get',
    baseURL
  });
}
/**
 *
 * @param params 【考勤项设置】修改
 * @returns
 */
export function PutAttendanceSetting(data: { list: Type.TAttendanceSetting }) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_reminder/setting/update',
    method: 'put',
    baseURL,
    data
  });
}

/**
 *
 * @param params 【其他设置】列表
 * @returns
 */
export function GetOtherSetting() {
  return ajaxService<Type.TOtherSetting>({
    url: '/hr/work_attendance/basic_setting/attendance_setting/other_settings/setting/list',
    method: 'get',
    baseURL
  });
}
/**
 *
 * @param params 【其他设置】修改
 * @returns
 */
export function PutOtherSetting(data: { list: Type.TOtherSetting }) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_cycle/classes/update',
    method: 'put',
    baseURL,
    data
  });
}

/**
 *
 * @param params 【考勤周期】列表
 * @returns
 */
export function GetAttendanceCycle(params: {
  name?: string;
  pageNumber?: number;
  pageSize?: number;
}) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_cycle/classes/list',
    method: 'get',
    baseURL,
    params
  });
}
/**
 *
 * @param params 【考勤周期】查重
 * @returns
 */
export function GetAttendanceCycleRepeat(params: { name?: string }) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_cycle/classes/repeat',
    method: 'get',
    baseURL,
    params
  });
}

/**
 *
 * @param params 【考勤周期】列表新增
 * @returns
 */
export function PostAttendanceCycle(data: {
  /**
   * 自定义结束  几号
   */
  endDay: number;
  /**
   * 自定义结束月 1 上个月 2 本月 3 下个月
   */
  endMouth: number;
  /**
   * 是否默认 1是 2否
   */
  isDefault: number;
  /**
   * 周期名称
   */
  name: string;
  /**
   * 自定义开始 几号
   */
  startDay: number;
  /**
   * 自定义开始月 1 上个月 2 本月 3 下个月
   */
  startMouth: number;
  /**
   * 状态 1、开启 2、停止
   */
  state: number;
  /**
   * 考勤周期设定（1、自然月 2、自定义）
   */
  type: number;
  [property: string]: any;
}) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_cycle/classes/add',
    method: 'post',
    baseURL,
    data
  });
}
/**
 *
 * @param params 【考勤周期】列表修改
 * @returns
 */
export function PutAttendanceCycle(data: {
  /**
   * 自定义结束  几号
   */
  endDay: number;
  /**
   * 自定义结束月 1 上个月 2 本月 3 下个月
   */
  endMouth: number;
  /**
   * 主键id
   */
  id: number;
  /**
   * 是否默认 1是 2否
   */
  isDefault: number;
  /**
   * 周期名称
   */
  name: string;
  /**
   * 自定义开始 几号
   */
  startDay: number;
  /**
   * 自定义开始月 1 上个月 2 本月 3 下个月
   */
  startMouth: number;
  /**
   * 状态 1、开启 2、停止
   */
  state: number;
  /**
   * 考勤周期设定（1、自然月 2、自定义）
   */
  type: number;
  [property: string]: any;
}) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_cycle/classes/update',
    method: 'put',
    baseURL,
    data
  });
}

/**
 *
 * @param params 【考勤周期】列表删除
 * @returns
 */
export function DelAttendanceCycle(data: { ids: number[] }) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/attendance_cycle/classes/delete',
    method: 'DELETE',
    baseURL,
    data
  });
}

/**
 *
 * @param params 【工作日历】列表
 * @returns
 */
export function GetWorkCalendarList(params: {
  name?: string;
  pageNumber?: number;
  pageSize?: number;
}) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/work_calendar/calendar/list',
    method: 'get',
    baseURL,
    params
  });
}
/**
 *
 * @param params 【工作日历】查重
 * @returns
 */
export function GetWorkCalendarRepeat(params: { name?: string }) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/work_calendar/calendar/repeat',
    method: 'get',
    baseURL,
    params
  });
}

/**
 *
 * @param params 【工作日历】列表新增
 * @returns
 */
export function PostWorkCalendar(data: Type.TWorkCalendarData) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/work_calendar/calendar/add',
    method: 'post',
    baseURL,
    data
  });
}
/**
 *
 * @param params 【工作日历】列表修改
 * @returns
 */
export function PutWorkCalendar(data: Type.TWorkCalendarData) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/work_calendar/calendar/update',
    method: 'put',
    baseURL,
    data
  });
}

/**
 *
 * @param params 【工作日历】列表删除
 * @returns
 */
export function DelWorkCalendar(data: { ids: number[] }) {
  return ajaxService({
    url: '/hr/work_attendance/basic_setting/attendance_setting/work_calendar/calendar/delete',
    method: 'DELETE',
    baseURL,
    data
  });
}

/**
 *
 * @param params 第三方接口 获取指定年份的指定类型节假日及万年历信息
 * @returns
 */
export function GetHoliday(date: number) {
  return ajaxService({
    url: `api/holiday/list/year/${date}`,
    method: 'get',
    baseURL: 'https://www.mxnzp.com',
    params: {
      app_id: 'lq1telfvvzqkzsne',
      app_secret: 'mQSrrryXQdl66kfG2iO44R21pTNXUwtm'
    }
  });
}

/**
 *
 * @param params 第三方接口  获取指定月份的节假日及万年历信息
 * @returns ignoreHoliday 是否忽略节假日，仅仅获取万年历，默认值false
 */
export function GetPerpetualCalendarMonth(
  date: number,
  ignoreHoliday: boolean
) {
  return ajaxService({
    url: `api/holiday/list/month/${date}`,
    method: 'get',
    baseURL: 'https://www.mxnzp.com',
    params: {
      app_id: 'lq1telfvvzqkzsne',
      app_secret: 'mQSrrryXQdl66kfG2iO44R21pTNXUwtm',
      ignoreHoliday
    }
  });
}

/**
 *
 * @param params 【工作日历】假日
 * @returns
 */
export function GetPerpetualCalendar(params: { year: number }) {
  return ajaxService({
    url: `/hr/work_attendance/basic_setting/attendance_setting/work_calendar/calendar/holiday`,
    method: 'get',
    baseURL,
    params
  });
}

/**
 *
 * @param params  地理编码
 * @returns
 */
export function GetMapAddress(params: { address: string; city?: string }) {
  return ajaxService({
    url: `/geocode/geo`,
    method: 'get',
    baseURL: '/v3',
    params: {
      ...params,
      ...mapBase
    }
  });
}

/**
 *
 * @param params  ip获取经纬度
 * @returns
 */
export function GetMapIpAddress(params?: { ip?: string }) {
  return ajaxService({
    url: `/ip`,
    method: 'get',
    baseURL: '/v3',
    params: {
      ...params,
      ...mapBase
    }
  });
}

/**
 *
 * @param params  【考勤机管理】列表
 * @returns
 */
export function GetMachineList(params: {
  pageNumber: number;
  pageSize: number;
  name?: string;
}) {
  return ajaxService({
    url: `/hr/work_attendance/basic_setting/attendance_setting/attendance_machine/machine/list`,
    method: 'get',
    baseURL,
    params
  });
}

/**
 *
 * @param params  【考勤机管理】删除
 * @returns
 */
export function DelMachineList(data: { ids: number[] }) {
  return ajaxService({
    url: `/hr/work_attendance/basic_setting/attendance_setting/attendance_machine/machine/delete`,
    method: 'delete',
    baseURL,
    data
  });
}

/**
 *
 * @param params  【考勤机管理】查重
 * @returns
 */
export function GetMachineRepeat(params: { name: string }) {
  return ajaxService({
    url: `/hr/work_attendance/basic_setting/attendance_setting/attendance_machine/machine/repeat`,
    method: 'get',
    baseURL,
    params
  });
}

/**
 *
 * @param params  【考勤机管理】删除
 * @returns
 */
export function PostMachine(data: {
  /**
   * 管理员用户id
   */
  manager: number;
  /**
   * 型号
   */
  model: string;
  /**
   * 名称
   */
  name: string;
  /**
   * 密码
   */
  password: string;
  /**
   * 设备sn号
   */
  sn: string;
}) {
  return ajaxService({
    url: `/hr/work_attendance/basic_setting/attendance_setting/attendance_machine/machine/add`,
    method: 'post',
    baseURL,
    data
  });
}

/**
 *
 * @param params  【考勤机管理】删除
 * @returns
 */
export function PutMachine(data: {
  id: number;
  /**
   * 管理员用户id
   */
  manager: number;
  /**
   * 型号
   */
  model: string;
  /**
   * 名称
   */
  name: string;
  /**
   * 密码
   */
  password: string;
  /**
   * 设备sn号
   */
  sn: string;
}) {
  return ajaxService({
    url: `/hr/work_attendance/basic_setting/attendance_setting/attendance_machine/machine/update`,
    method: 'put',
    baseURL,
    data
  });
}

/**
 *
 * @param params  【提醒设置】列表
 * @returns
 */
export function GetReminderSetting() {
  return ajaxService<Type.TReminder>(
    {
      url: `/hr/work_attendance/basic_setting/holiday_setting/reminder_setting/setting/list`,
      method: 'get',
      baseURL
    },
    { message: '查询成功', mode: 'info' }
  );
}

/**
 *
 * @param params  【提醒设置】修改
 * @returns
 */
export function PutReminderSetting(data: { list: Type.TReminder }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/basic_setting/holiday_setting/reminder_setting/setting/update`,
      method: 'put',
      baseURL,
      data
    },
    { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【打卡方式地址】列表
 * @returns
 */
export function GetAddressList(params: {
  pageNumber: number;
  pageSize: number;
  name?: string;
}) {
  return ajaxService(
    {
      url: `/hr/work_attendance/basic_setting/attendance_setting/clock_in/clock/list`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【打卡方式地址】修改
 * @returns
 */
export function PutAddressData(data: Type.TAddress) {
  return ajaxService(
    {
      url: `/hr/work_attendance/basic_setting/attendance_setting/clock_in/clock/update`,
      method: 'PUT',
      baseURL,
      data
    },
    { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【打卡方式地址】新增
 * @returns
 */
export function PostAddressData(data: Type.TAddress) {
  return ajaxService(
    {
      url: `/hr/work_attendance/basic_setting/attendance_setting/clock_in/clock/add`,
      method: 'post',
      baseURL,
      data
    },
    { message: '新增成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【打卡方式地址】删除
 * @returns
 */
export function DelAddressData(data: { ids: number[] }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/basic_setting/attendance_setting/clock_in/clock/delete`,
      method: 'DELETE',
      baseURL,
      data
    },
    { message: '删除成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【打卡方式地址】列表
 * @returns
 */
export function RepeatAddressList(params: {
  name: string;
  attendanceClockInId?: number;
}) {
  return ajaxService(
    {
      url: `/hr/work_attendance/basic_setting/attendance_setting/clock_in/clock/repeat`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【考勤组列表】列表
 * @returns
 */
export function GetClassesList(params: {
  name: string;
  pageNumber: number;
  pageSize: number;
}) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_groups_list/classes/list`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【考勤组列表】列表
 * @returns
 */
export function RepeatClassesList(params: { name: string }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_groups_list/classes/repeat`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【考勤组列表】新增
 * @returns
 */
export function PostClasses(data: Type.TClasses) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_groups_list/classes/add`,
      method: 'post',
      baseURL,
      data
    },
    { message: '新增成功', mode: 'success' }
  );
}
/**
 *
 * @param data  【考勤组列表】修改
 * @returns
 */
export function PutClasses(data: Type.TClasses) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_groups_list/classes/update`,
      method: 'put',
      baseURL,
      data
    },
    { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【考勤组列表】删除
 * @returns
 */
export function DelClasses(data: { ids: number[] }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_groups_list/classes/delete`,
      method: 'DELETE',
      baseURL,
      data
    },
    { message: '删除成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【考勤豁免】用户搜索列表
 * @returns
 */
export function GetAttendanceRemitUserList(params: {
  /**
   * 适用部门 1 是 2否
   */
  applicableDepartment?: number;
  /**
   * 适用人员 1 是 2否
   */
  applicableEmployee?: number;
  /**
   * 考勤组id
   */
  attendanceTeamId?: number;
  /**
   * 部门id
   */
  departmentId?: number;
  name?: string;
  pageNumber?: number;
  pageSize?: number;
  /**
   * 搜索类型 1在分组里面 (默认)   2不在分组里面
   */
  searchType?: number;
  /**
   * 类型 1正常打卡 2 豁免打卡
   */
  type?: number;
}) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_remit/user/list`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【考勤豁免】列表
 * @returns
 */
export function GetRemitList(params: {
  name: string;
  pageNumber: number;
  pageSize: number;
}) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_remit/classes/list`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【考勤豁免】新增
 * @returns
 */
export function PostRemit(data: Type.TRemit) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_remit/classes/add`,
      method: 'post',
      baseURL,
      data
    },
    { message: '新增成功', mode: 'success' }
  );
}
// /**
//  *
//  * @param data  【考勤豁免】修改
//  * @returns
//  */
// export function PutRemit(data: Type.TClasses) {
//   return ajaxService(
//     {
//       url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_groups_list/classes/update`,
//       method: 'put',
//       baseURL,
//       data
//     },
//     { message: '修改成功', mode: 'success' }
//   );
// }

/**
 *
 * @param data  【考勤豁免】删除
 * @returns
 */
export function DelRemit(data: { ids: number[] }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_section/attendance_remit/classes/delete`,
      method: 'DELETE',
      baseURL,
      data
    },
    { message: '删除成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【班次管理】列表
 * @returns
 */
export function GetClassesManage(params: {
  type?: 1 | 2 | 3 | 4;
  name?: string;
  pageNumber: number;
  pageSize: number;
}) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/classes_manage/classes/list`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param params  【班次管理】查重
 * @returns
 */
export function RepeatClassesManage(params: { name: string }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/classes_manage/classes/repeat`,
      method: 'get',
      baseURL,
      params
    }
    // { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【班次管理】新增
 * @returns
 */
export function PostClassesManage(data: Type.TClassesManage) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/classes_manage/classes/add`,
      method: 'post',
      baseURL,
      data
    },
    { message: '新增成功', mode: 'success' }
  );
}
/**
 *
 * @param data  【班次管理】修改
 * @returns
 */
export function PutClassesManage(data: Type.TClassesManage) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/classes_manage/classes/update`,
      method: 'put',
      baseURL,
      data
    },
    { message: '修改成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【班次管理】删除
 * @returns
 */
export function DelClassesManage(data: { ids: number[] }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/classes_manage/classes/delete`,
      method: 'DELETE',
      baseURL,
      data
    },
    { message: '删除成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【补卡规则】列表
 * @returns
 */
export function GetReissueCardRule(params: {
  pageNumber: number;
  pageSize: number;
}) {
  return ajaxService({
    url: `/hr/work_attendance/attendance_manage/attendance_rules/reissue_card_rule/rule/list`,
    method: 'GET',
    baseURL,
    params
  });
}

interface TReissueCardRule {
  /**
   * 补卡申请规则
   */
  applyRule: {
    /**
     * 天数
     */
    day: number;
    /**
     * 次数
     */
    frequency: number;
    [property: string]: any;
  };
  attendanceRuleMember: {
    /**
     * 适用部门 1 是 2否
     */
    applicableDepartment: number;
    /**
     * 适用人员 1 是 2否
     */
    applicableEmployee: number;
    /**
     * 部门id
     */
    departmentId: number;
    id: number;
    /**
     * 规则id
     */
    ruleId: number;
    /**
     * 类型 1补卡规则 2加班规则 3外出出差规则 4销卡规则
     */
    type: number;
    /**
     * 用户id
     */
    userId: number;
    [property: string]: any;
  }[];
  id: number;
  /**
   * 仅允许工作时间内补卡
   */
  isOnlyAllowed: number;
  /**
   * 规则名称
   */
  name: string;
  /**
   * 范围类型 1全体 2部分员工
   */
  scope: number;
  /**
   * 状态 1、开启 2、停止
   */
  state: number;
  [property: string]: any;
}

/**
 *
 * @param data  【补卡规则】列表
 * @returns
 */
export function PutReissueCardRule(data: TReissueCardRule) {
  return ajaxService({
    url: `/hr/work_attendance/attendance_manage/attendance_rules/reissue_card_rule/rule/update`,
    method: 'PUT',
    baseURL,
    data
  });
}

/**
 *
 * @param data  【补卡规则】列表新增
 * @returns
 */
export function PostReissueCardRule(data: TReissueCardRule) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_rules/reissue_card_rule/rule/add`,
      method: 'POST',
      baseURL,
      data
    },
    { message: '新增成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【补卡规则】列表新增
 * @returns
 */
export function DelReissueCardRule(data: { ids: number[] }) {
  return ajaxService(
    {
      url: `/hr/work_attendance/attendance_manage/attendance_rules/reissue_card_rule/rule/delete`,
      method: 'DELETE',
      baseURL,
      data
    },
    { message: '删除成功', mode: 'success' }
  );
}

/**
 *
 * @param data  【补卡规则】查重
 * @returns
 */
export function RepeatReissueCardRule(params: { name: string }) {
  return ajaxService({
    url: `/hr/work_attendance/attendance_manage/attendance_rules/reissue_card_rule/rule/repeat`,
    method: 'GET',
    baseURL,
    params
  });
}
